package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.PushInfo;
import com.ruoyi.system.mapper.PushInfoMapper;
import com.ruoyi.system.service.PushInfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (PushInfo)表服务实现类
 *
 * @author makejava
 * @since 2023-05-31 16:46:22
 */
@Service("pushInfoService")
public class PushInfoServiceImpl implements PushInfoService {
    @Resource
    private PushInfoMapper pushInfoMapper;

    @Override
    public List<PushInfo> selectAll(PushInfo pushInfo) {
        return pushInfoMapper.selectAll(pushInfo);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PushInfo queryById(Integer id) {
        return this.pushInfoMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pushInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PushInfo> queryByPage(PushInfo pushInfo, PageRequest pageRequest) {
        long total = this.pushInfoMapper.count(pushInfo);
        return new PageImpl<>(this.pushInfoMapper.queryAllByLimit(pushInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pushInfo 实例对象
     * @return 实例对象
     */
    @Override
    public PushInfo insert(PushInfo pushInfo) {
        this.pushInfoMapper.insert(pushInfo.getPushInfo());
        return pushInfo;
    }

    /**
     * 修改数据
     *
     * @param pushInfo 实例对象
     * @return 实例对象
     */
    @Override
    public PushInfo update(PushInfo pushInfo) {
        this.pushInfoMapper.update(pushInfo);
        return this.queryById(pushInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.pushInfoMapper.deleteById(id) > 0;
    }
}
